﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="agentlist.aspx.cs" Inherits="UI.system.page.agent.agentlist" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/system/js/jquery.min.js"></script>
    <script src="/system/layui/layui.js"></script>
    <script src="/system/js/common.js"></script>
    <script src="/system/js/md5.js"></script>
    <link rel="stylesheet" href="/system/layui/css/layui.css">
    <link rel="stylesheet" href="/system/css/iframe.css">
    <style>
        td img{ width:40px; height:40px; float:left; margin-left:5px;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="layer-toolbar">
        <div class="layer-toolbar-left">
        <a class="layui-btn layui-btn-small" onclick="Save_Agent(0)">新增代理商信息</a>
        </div>
        <div class="layer-toolbar-right">
            <input id="keyword" type="text" name="title" placeholder="代理商姓名" autocomplete="off" class="layui-input" value=""  style="width:150px;" onkeyup='CRM.Enter("#search")'>
            <a id="search" class="layui-btn layui-btn-small layui-btn-normal" onclick="Search()">搜索</a>
            <a class="layui-btn layui-btn-small" onclick="Search()">刷新</a>
        </div>
    </div>
    <div id="iframe" class="layer-iframe">
    <div class="layui-form">
    <table class="layui-table">
    <colgroup>
      <col>
      <col width="150">
      <col width="150">
      <col width="150">
      <col width="180">
      <col width="180">
    </colgroup>
    <thead>
      <tr>
        <th>代理商姓名</th>
        <th>代理商电话</th>
        <th>代理商微信</th>
        <th>代理商二维码</th>
        <th>修改时间</th>
        <th>操作</th>
      </tr> 
    </thead>
     <tbody id="layer-table">
        <tr><td colspan="6" class="center">数据加载中...</td></tr>
    </tbody>
    <script id="data-table" type="text/html">
      {{#  layui.each(d, function(index, item){ }}
      <tr>
        <td>{{item.AgentName}}</td>
        <td>{{item.Mobile}}</td>
        <td>{{item.WeChat}}</td>
        <td><img src="{{item.QRCode}}"/></td>
        <td>{{item.CreateDate}}</td>
        <td>
        <a class="layui-btn layui-btn-mini" onclick="Save_Agent({{item.ID}})">编辑</a>
        <a class="layui-btn layui-btn-mini layui-btn-danger" onclick="Delete_Agent(this,{{item.ID}})">删除</a>
        </td>
      </tr>
      {{#  }); }}
      </script>
  </table>
    </div>
    </div>
    <div id="layer-page" class="layer-page"></div>
    </form>
    <script>
        layui.use('form', function () {
            var $ = layui.jquery, form = layui.form();

            //全选
            form.on('checkbox(allChoose)', function (data) {
                var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
                child.each(function (index, item) {
                    item.checked = data.elem.checked;
                });
                form.render('checkbox');
            });
            Init_Pager(1);
        });

        function Init_Pager(pageindex) {
            var data = {};
            data.act = "Find_Agent";
            data.pageindex = pageindex;
            data.keyword = $("#keyword").val();
            data.sign = GetSign(data.act);
            Loading();
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
                var json = $.parseJSON(r);
                if (json.state) {
                    Pager(json.data.list, json.data.count);
                }
                else {
                    LayerBox.Error(json.msg);
                }
            });
        };
        function Save_Agent(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/agent/agentadd.aspx?id=" + id, function (html) {
                LayerBox.Close.ByAll();
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title + "代理商信息", html, 390, 470, null, function (form) {
                    var data = form;
                    data.act = "Save_Agent";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    if (id == 0) {
                        data.agentname = window.parent.$("#agentname").find("option:selected").text();
                    } else {
                        data.agentname = window.parent.$("#agentnames").find("option:selected").text();
                    }
                    data.img = window.parent.$(".img_container img").attr("src");
                    if (data.img == "") {
                        LayerBox.Error("请上传二维码");
                        return;
                    }
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
                var upload = new window.parent.Upload_File("upload_img");
                upload.swfu.handle = "upload_active";
            });
        };

        function Delete_Agent(o, id) {
            LayerBox.Confirm("您确定要删除吗？", function () {
                Delete_Table(o, id, "Delete_Agent");
            });
        };
</script>
</body>
</html>
